%% Parameters
% [filename path] = uigetfile('*.*');
% filename = [path filename]

% Lab-PC
filename = 'D:\Server\FTP_server\Temp\origianl_maritx_01.fid\fid'
% filename = 'D:\Server\FTP_server\20130930_KSJ_CSI2D_test01\8by8M_20by50F_Water_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131009_KSJ_NAA_CSI2D_RatBrainCoil01\origianl_maritx_volCoil_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131015_KSJ_CSI2D_Gly_Cr_NAA_50mM_Phantom01\16by8M_35by20F_TR4s_2gain_Water_SatBand_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131009_KSJ_NAA_CSI2D_RatBrainCoil01\origianl_maritx_volCoil_sqaure_01.fid\fid'

% Home-PC
% filename = 'D:\Server\FTP_server\Temp\origianl_maritx_01.fid\fid'
% filename = 'D:\Server\FTP_server\20130930_KSJ_CSI2D_test01\8by8M_20by50F_Water_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131009_KSJ_NAA_CSI2D_RatBrainCoil01\origianl_maritx_volCoil_01.fid\fid'
% filename = 'D:\Workspace\MRSI\Data\20131015_KSJ_CSI2D_Gly_Cr_NAA_50mM_Phantom01\16by8M_35by20F_TR4s_2gain_Water_SatBand_01.fid\fid'
% filename = 'D:\Server\FTP_server\20131009_KSJ_NAA_CSI2D_RatBrainCoil01\origianl_maritx_volCoil_sqaure_01.fid\fid'

% Read a single fid file 
[mrsi, info] = mrsi2Drecon(filename, 1);

nblocks=info{1, 1}(1); % header info
ntraces=info{1, 1}(2); % status info
dataP=info{1, 1}(3)/2; % data points

% adjust position
mrsi = circshift(mrsi, [0, 4]);
    
%% display single spectrum
% a=mrsi(5,3,:);
% b = squeeze(a);
% 
% 
% figure(2);
% plot(real(b));

%% separated multi-plot
% figure(4);
% for indx_trace= 1:1:ntraces
%     for indx_block = 1:1:nblocks
%         subplot(ntraces, nblocks, (indx_trace-1)*nblocks+(indx_block));
%         temp = squeeze(mrsi(indx_trace, indx_block, :));
%         plot(abs(temp));
%         set(gca, 'box', 'off');
%         set(gca,'xtick',[],'ytick',[])
%         ylim([0,2000000]);
%         xlim([0,2040]);
%     end
% end

%% Display height
% figure(1);
% handaxes = axes('position', [0.1 0.1 0.8 0.8]);
% imagesc(abs(mrsi(:,:,1030)));
% colormap('gray');

%% Display spectra on a grid
figure(2);
handaxes2 = axes('position', [0.1 0.1 0.8 0.8]);
set(gca,'xtick',[],'ytick',[])
integral_spec = zeros(ntraces, nblocks);

if ntraces > nblocks
    for indx_trace= 1:1:ntraces
        for indx_block = 1:1:nblocks
            handaxes_sub = axes('position', [0.1+0.8/nblocks*(indx_block-1) 0.8-0.8/ntraces*(indx_trace-2) 0.8/nblocks 0.8/ntraces]);
            integral_spec(indx_trace, indx_block) = sum(abs(squeeze(mrsi(indx_trace, indx_block, 1020:1040))));
            plot(abs(squeeze(mrsi(indx_trace, indx_block, :))));
            set(handaxes_sub, 'box', 'off');
            set(gca,'xtick',[],'ytick',[])
            ylim([0,10000000/2]);
            xlim([0,2048]);
        end
    end
elseif nblocks > ntraces
    for indx_trace= 1:1:ntraces
        for indx_block = 1:1:nblocks
            handaxes_sub = axes('position', [0.1+0.8/nblocks*(indx_block-1) 0.8-0.8/ntraces*(indx_trace-1) 0.8/nblocks 0.8/ntraces]);
            integral_spec(indx_trace, indx_block) = sum(abs(squeeze(mrsi(indx_trace, indx_block, 1020:1040))));
            plot(abs(squeeze(mrsi(indx_trace, indx_block, :))));
            set(handaxes_sub, 'box', 'off');
            set(gca,'xtick',[],'ytick',[])
            ylim([0,10000000/3]);
            xlim([0,2048]);
        end
    end
end


%% show a gray image
figure(3);
imagesc(integral_spec);
colormap('gray');

%% display magnitude spectra
% figure(5)
% plot(abs(squeeze(mrsi(6, 11, :)));
% 
% figure(6)
% plot(abs(squeeze(mrsi(6, 10, :))));
% 
% figure(7)
% plot(abs(squeeze(mrsi(6, 9, :))));

%% remove the used parameters 
clear;





